home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kpanelmenu.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  6.8 KB  |  183 lines

  1. /*****************************************************************
  2.  
  3. Copyright (c) 1996-2000 the kicker authors. See file AUTHORS.
  4.           (c) 2001 Michael Goffioul <kdeprint@swing.be>
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  19. AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #ifndef __KPANELMENU_H__
  26. #define __KPANELMENU_H__
  27.  
  28. #include <qstring.h>
  29. #include <kpopupmenu.h>
  30. #include <kgenericfactory.h>
  31.  
  32. class KPanelMenuPrivate;
  33.  
  34. /**
  35.  * @short Base class to build dynamically loaded menu entries for the K-menu, or the panel.
  36.  *
  37.  * This class allows to build menu entries that will be dynamically added either to
  38.  * the K-menu, or to the panel as a normal button. These dynamic menus are located
  39.  * in shared libraries that will be loaded at runtime by Kicker (the %KDE panel).
  40.  *
  41.  * To build such a menu, you have to inherit this class and implement the pure virtual
  42.  * functions #initialize() and slotExec(). You also have to provide a factory
  43.  * object in your library, see KLibFactory. This factory is only used to construct
  44.  * the menu object.
  45.  *
  46.  * Finally, you also have to provide a desktop file describing your dynamic menu. The
  47.  * relevant entries are: Name, Comment, Icon and X-KDE-Library (which contains the
  48.  * library name without any extension). This desktop file has to be installed in
  49.  * $KDEDIR/share/apps/kicker/menuext/.
  50.  *
  51.  * @author The kicker maintainers, Michael Goffioul <kdeprint@swing.be>
  52.  */
  53. class KDEUI_EXPORT KPanelMenu : public KPopupMenu
  54. {
  55.     Q_OBJECT
  56.  
  57. public:
  58.     /**
  59.      * Construct a KPanelMenu object. This is the normal constructor to use when
  60.      * building extrernal menu entries.
  61.      */
  62.     KPanelMenu(QWidget *parent=0, const char *name=0);
  63.     /**
  64.      * Constructor used internally by Kicker. You don't really want to use it.
  65.      * @param startDir a directory to associate with this menu
  66.      * @param parent parent object
  67.      * @param name name of the object
  68.      * @see path(), setPath()
  69.      */
  70.     KPanelMenu(const QString &startDir, QWidget *parent=0, const char *name=0);
  71.     /**
  72.      * Destructor.
  73.      */
  74.     virtual ~KPanelMenu();
  75.  
  76.     /**
  77.      * Get the directory path associated with this menu, or QString::null if
  78.      * there's no such associated path.
  79.      * @return the associated directory path
  80.      * @see setPath()
  81.      */
  82.     const QString& path() const;
  83.     /**
  84.      * Set a directory path to be associated with this menu.
  85.      * @param p the directory path
  86.      * @see path()
  87.      */
  88.     void setPath(const QString &p);
  89.     /**
  90.      * Tell if the menu has been initialized, that is it already contains items.
  91.      * This is useful when you need to know if you have to clear the menu, or to
  92.      * fill it.
  93.      * @return the initial state
  94.      * @see setInitialized(), initialize()
  95.      */
  96.     bool initialized() const;
  97.     /**
  98.      * Set the initial state. Set it to true when you menu is filled with the items
  99.      * you want.
  100.      * @param on the initial state
  101.      * @see initialized(), initialize()
  102.      */
  103.     void setInitialized(bool on);
  104.  
  105.     /**
  106.      * Disable the automatic clearing of the menu. Kicker uses a cache system for
  107.      * its menus. After a specific configurable delay, the menu will be cleared.
  108.      * Use this function if you want to disable kicker's cache system, and avoid
  109.      * the clearing of your menu.
  110.      */
  111.     void disableAutoClear();
  112.  
  113. public slots:
  114.     /**
  115.      * Reinitialize the menu: the menu is first cleared, the initial state is set
  116.      * to false, and finally #initialize() is called. Use this if you want to
  117.      * refill your menu immediately.
  118.      */
  119.     void reinitialize();
  120.     /**
  121.      * Deinitialize the menu: the menu is cleared and the initialized state is set to
  122.      * false. #initialize() is NOT called. It will be called before the menu is
  123.      * next shown, however. Use this slot if you want a delayed reinitialization.
  124.      * @since 3.1
  125.      */
  126.     void deinitialize();
  127.  
  128. protected slots:
  129.     /**
  130.      * This slot is called just before the menu is shown. This allows your menu
  131.      * to update itself if needed. However you should instead re-implement
  132.      * #initialize to provide this feature. This function is responsible for
  133.      * the cache system handling, so if you re-implement it, you should call
  134.      * the base function also. Calls #initialize().
  135.      * @see disableAutoClear()
  136.      */
  137.     virtual void slotAboutToShow();
  138.     /**
  139.      * This is slot is called when an item from the menu has been selected. Your
  140.      * applet is then supposed to perform some action. You must re-implement this
  141.      * function.
  142.      * @param id the ID associated with the selected item
  143.      */
  144.     virtual void slotExec(int id) = 0;
  145.     /**
  146.      * This slots is called to initialize the menu. It is called automatically by
  147.      * slotAboutToShow(). By re-implementing this functions, you can reconstruct
  148.      * the menu before it is being shown. At the end of this function, you should
  149.      * call setInitialize() with true to tell the system that the menu is OK.
  150.      * You applet must re-implement this function.
  151.      * @see slotAboutToShow(), initialized(), setInitialized()
  152.      */
  153.     virtual void initialize() = 0;
  154.     /**
  155.      * Clears the menu, and update the initial state accordingly.
  156.      * @see initialized()
  157.      */
  158.     void slotClear();
  159.  
  160. protected:
  161.     /**
  162.      * Re-implemented for internal reasons.
  163.      */
  164.     virtual void hideEvent(QHideEvent *ev);
  165.     /**
  166.      * For internal use only. Used by constructors.
  167.      */
  168.     void init(const QString& path = QString::null);
  169.  
  170. protected:
  171.     virtual void virtual_hook( int id, void* data );
  172. private:
  173.     void internalInitialize();
  174.     KPanelMenuPrivate *d;
  175. };
  176.  
  177. #define K_EXPORT_KICKER_MENUEXT( libname, classname )                       \
  178.     K_EXPORT_COMPONENT_FACTORY(                                             \
  179.         kickermenu_##libname,                                               \
  180.         KGenericFactory<classname>("libkickermenu_" #libname) )
  181.  
  182. #endif
  183.